import cv2 as cv
import numpy as np


def draw_line_demo(image):
    width, height = image.shape[:2]
    color = (0, 0, 255)
    cv.line(image, (0, 0), (height - 1,width - 1), color, 2)
    cv.imshow('line', image)


def draw_circle_demo(image):
    width, height = image.shape[:2]
    center = (np.int(height / 2),np.int(width / 3 * 2))
    color = (0, 255, 255)
    radius = np.minimum(np.int(width / 4), np.int(height / 4))
    cv.circle(image, center, radius, color, 2)
    cv.imshow('circle', image)


def draw_rectangle_demo(image):
    width, height = image.shape[:2]
    pt1 = ( np.int(height / 3),np.int(width / 3))
    pt2 = ( np.int(height / 3 * 2),np.int(width / 3 * 2))
    color = (255, 0, 0)
    cv.rectangle(image, pt1, pt2, color, 2)
    cv.imshow('rectangle', image)


def draw_ellipse_demo(image):
    width, height = image.shape[:2]
    center = ( np.int(height / 2),np.int(width / 2))
    color = (255, 255, 0)
    cv.ellipse(image, center, (100, 60), 0, 0, 360, color, 2)
    cv.imshow('ellipse', image)


def draw_polylines_demo(image):
    pts = np.array([[15, 20], [100, 59], [200, 190], [39, 180]], np.int32)
    pts = pts.reshape((-1, 1, 2))
    print(pts)
    color = (255, 0, 255)
    cv.polylines(image, [pts], True, color, thickness=2)
    cv.imshow('polylines', image)


def putext_demo(image):
    cv.putText(image, 'Cv', (80, 240), cv.FONT_HERSHEY_SIMPLEX, 3, (255, 255, 255), 3)
    cv.imshow('putext', image)


def demo_simple(image):
    draw_line_demo(src)
    draw_circle_demo(src)
    draw_rectangle_demo(src)
    draw_ellipse_demo(src)
    draw_polylines_demo(src)
    putext_demo(src)


src = np.zeros([400, 500, 3], np.uint8)
cv.namedWindow('demo', cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
demo_simple(src)
cv.waitKey(0)
cv.destroyAllWindows()
